<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<base href="<%=basePath%>">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript">
//价格 日期验证
function isValidateDate() {
	$("#moneytip").html("");
	$("#timetip").html("");
	var money = $.trim($("#money").val());
	if(isNaN(money)){
		$("#moneytip").html("价格格式不正确");
		return false;
	}
	var time = $("#time").val();
    var date = $.trim(time);
    var reg = /^(\d{4})-(\d{2})-(\d{2})$/;
    reg.exec(date);
    if (!reg.test(date) && RegExp.$2 <= 12 && RegExp.$3 <= 31) {
    	$("#timetip").html("日期格式不正确");
        return false;
    }
    var year, month, day;
    year = parseInt(date.split("-")[0], 10);
    month = parseInt(date.split("-")[1], 10);
    day = parseInt(date.split("-")[2], 10);
    if (! ((1 <= month) && (12 >= month) && (31 >= day) && (1 <= day))) {
    	$("#timetip").html("日期格式不正确");
        return false;
    }
    if ((month <= 7) && ((month % 2) == 0) && (day >= 31)) {
    	$("#timetip").html("日期格式不正确");
        return false;
    }
    if ((month >= 8) && ((month % 2) == 1) && (day >= 31)) {
    	$("#timetip").html("日期格式不正确");
        return false;
    }
    if (month == 2) {
        if ((year % 400 == 0) || ((year % 4 == 0) && (year % 100 != 0))) {
            if (day > 29) {
            	$("#timetip").html("日期格式不正确");
                return false;
            }
        } else {
            if (day > 28) {
            	$("#timetip").html("日期格式不正确");
                return false;
            }
        }
    }
    return true;
}
</script>
</head>
<body>

<div>
	<form action="addNewItems.action" method="post" onsubmit="return isValidateDate();">
		商品名称:<input type="text" name="name"><br>
		商品价格:<input type="text" name="price" id="money"><span id="moneytip"></span><br>
		商品图片:<input type="text" name="pic"><br>
		生产日期:<input type="text" name="createtime" id="time"><span id="timetip"></span><br>
		商品描述:<input type="text" name="detail"><br>
		<br>
		<input type="submit" value="新增">&nbsp;<input type="reset">
	</form>
</div>
<a href="itemsList.jsp">返回</a>
</body>
</html>